package com.ddwl.user.dao;

import com.ddwl.common.dao.TkDao;
import com.ddwl.user.dao.mapper.UserStatusMapper;
import com.ddwl.user.dao.model.UserStatus;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class UserStatusDao extends TkDao<UserStatusMapper, UserStatus> {

    @Resource
    private UserStatusMapper userStatusMapper;

    /**
     * 更新身份信息通过id
     *
     * @param userStatus
     */
    public void updateIdCardById(UserStatus userStatus) {
        userStatusMapper.updateIdCardById(userStatus);
    }

    /**
     * 更新身份信息通过UserID
     *
     * @param userStatus
     */
    public void updateIdCardByUserId(UserStatus userStatus) {
        userStatusMapper.updateIdCardByUserId(userStatus);
    }


    /**
     * 获取用户状态
     *
     * @param userId
     * @return
     */
    public UserStatus getUserStatus(String userId) {
        UserStatus query = new UserStatus();
        query.setUserId(userId);
        UserStatus userStatus = selectOne(query);
        if (userStatus == null) {
            userStatus = initUserStatus(userId);
        }
        return userStatus;
    }


    public UserStatus initUserStatus(String userId) {
        UserStatus userStatus = UserStatus.initUserStatus(userId);
        insert(userStatus);
        return userStatus;
    }


}
